home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / NextAnswers / 1398_controlling_windows_edit_status_in_a_menu_cell.rtf < prev    next >
Text File  |  1993-11-08  |  3KB  |  95 lines

  1. {\rtf0\ansi{\fonttbl\f0\fnil Times-Roman;\f1\fmodern Courier;\f2\fmodern Ohlfs;}
  2. \paperw11640
  3. \paperh10660
  4. \margl120
  5. \margr120
  6. {\colortbl;\red0\green0\blue0;\red81\green81\blue81;\red80\green80\blue80;}
  7. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f0\b0\i0\ulnone\fs28\fc0\cf0 Q:  I am using the Windows submenu. For each new window document that I create in my application, a new menu cell is added to the submenu with the window's title and a small X at the left-most edge of the menu cell.  How do I programmatically control this X to make it broken when the document associated with the menu cell has been changed?\
  8. \
  9. A:  The window method 
  10. \f1\fs24 setDocEdited: (BOOL)flag 
  11. \f0\fs28 is responsible for displaying the broken X when it is set to YES.  This method controls both the X in the menu cell, and the X on the upper right corner of the window.  It has to be reset to NO 
  12. \b before saving the document
  13. \b0 , so that the X reappears as non-broken. See the code snippet below:\
  14. \
  15.  
  16. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\f1\fs24\fc1\cf1 \
  17. /* In the case of a text object for example,this text delegate method is responsible for notifying that the document has changed. Please note that ruler and font changes as well as changes caused by spell checking the Text are not reflected by this text delegate method.\
  18. */\
  19. \
  20. - textDidChange: sender\
  21. \{\
  22.     [currentDocWindow setDocEdited:YES];\
  23.     return self;\
  24. \}\
  25. \
  26.  
  27. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0\cf0     
  28. \f0\fs28 \
  29.  
  30. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\f1\fs24\fc1\cf1 \
  31. \
  32. /*     Remember to reset setDocEdited to NO
  33. \b  before saving 
  34. \b0 your file, so that the X shows as a regular X 
  35. \b when reading the file back in.
  36. \b0 \
  37. */\
  38. \
  39. - saveFilename:(const char *)filename\
  40. \{\
  41.     [currentDocWindow setDocEdited:NO];\
  42.     \
  43.     /* To generate a textDidChange message */\
  44.     [currentDocWindow makeFirstResponder:currentDocWindow]; \
  45.     ........\
  46.     return self;\
  47. \}\
  48. \
  49. \
  50. /*     After setting setDocEdited to YES, the state of isDocEdited is YES. You can query this state and, if appropriate, display an alert panel before the window closes.  Note the use of NXStringTable here for ease of localization. Please refer to our user interface guidelines and release notes for more details.\
  51.     \
  52. */\
  53. \
  54. #define    SAVE    NX_ALERTDEFAULT\
  55. #define    CLOSE    NX_ALERTALTERNATE\
  56. #define    CANCEL    NX_ALERTOTHER\
  57. \
  58. - windowWillClose:sender\
  59. \{\
  60.     int result;\
  61.     \
  62.     if ([currentDocWindow isDocEdited]) \{\
  63.         if (!stringTable)\
  64.             stringTable = [[NXApp delegate] stringTable];\
  65.         result = NXRunAlertPanel([NXApp appName],\
  66.             [stringTable valueForStringKey:\
  67.             "The document %s has unsaved changes.\\nClose anyway?"],\
  68.             [stringTable valueForStringKey:"Save"],\
  69.             [stringTable valueForStringKey:"Close"],\
  70.             [stringTable valueForStringKey:"Cancel"],\
  71.             [currentDocWindow title]);\
  72.         switch(result) \{\
  73.             case SAVE:\
  74.                 ...\
  75.                 break;\
  76.             case CLOSE:\
  77.                 break;\
  78.             case CANCEL: \
  79.                 return nil;\
  80.             \}\
  81.         \}\
  82.     \
  83.     ......\
  84.     \
  85.     return self;\
  86. \}\
  87. \
  88. \
  89.  
  90. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f0\fs28\fc0\cf0 QA618\
  91. \
  92. Valid for 1,0, 2.0, 3.0\
  93. \
  94.  
  95.